package com.mitei.dao.sql;

import java.util.ArrayList;

public class Query {
	
	private String query = new String();
	private ArrayList<String> columns = new ArrayList<String>();
	private ArrayList<String> tables = new ArrayList<String>();
	private ArrayList<String> clauses = new ArrayList<String>();
	
	public Query(String query) {
		this.query = query;
	}
	
	public void addColumn(String column) {
		columns.add(column);
	}
	
	public void addTable(String table) {
		tables.add(table);
	}
	
	public void addClause(String clause) {
		clauses.add(clause);
	}
	
	public String getQuery() {
		//query
		query = query.trim();
		
		//add columns
		for(String col : columns) {
			query += " " + col;
			if (columns.indexOf(col) != (columns.size() - 1)) {
				query += ",";
			}
		}
		
		//add tables
		query += " FROM";
		for(String tab : tables) {
			query += " " + tab;
			if (tables.indexOf(tab) != (tables.size() - 1)) {
				query += ",";
			}
		}
		
		//add clauses
		query += " WHERE";
		for(String cl : clauses) {
			query += " " + cl;
			if (clauses.indexOf(cl) != (clauses.size() - 1)) {
				query += " AND";
			}
		}
		return query;
	}

}
